package com.iterator.service.wechat.wy.brand;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iterator.bean.wechat.wy.brand.Brand;
import com.iterator.bean.wechat.wy.brand.BrandExample;
import com.iterator.bean.wechat.wy.brand.BrandListBean;
import com.iterator.bean.wechat.wy.brand.BrandListVO;
import com.iterator.mapper.wechat.wy.brand.BrandMapperWy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Silence_W
 * @date: 2021-01-12 14:59
 **/
@Service
public class WXBrandServiceImpl implements WXBrandService {
    @Autowired
    BrandMapperWy brandMapperWy;
    @Override
    public BrandListVO queryBrand(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Brand> brands = brandMapperWy.selectByExample(new BrandExample());
        ArrayList<BrandListBean> brandListVOS = new ArrayList<>();
        for (Brand brand : brands) {
            brandListVOS.add(new BrandListBean(brand.getId(),brand.getName(),brand.getDesc(),brand.getPicUrl(),brand.getFloorPrice().doubleValue()));
        }
        PageInfo<BrandListBean> brandListBeanPageInfo = new PageInfo<>(brandListVOS);
      int total = (int) brandListBeanPageInfo.getTotal();
        return new BrandListVO(total,brandListVOS);
    }

    @Override
    public Brand queryBrandDetail(Integer id) {
        Brand brand = brandMapperWy.selectByPrimaryKey(id);
        return brand;
    }
}
